#pragma once
#include <stdexcept>

template<typename T>
class CSingleton
{
public:
	template<typename... Args>
	static T* CreateInstance(Args&&... args)
	{
		if (mInstance == nullptr)
		{
			mInstance = new T(std::forward<Args>(args)...);
		}
		return mInstance;
	}

	static T* GetInstance()
	{
		if (mInstance == nullptr)
		{
			throw std::logic_error("instance is not create");
		}
		return mInstance;
	}

	static void DestroyInstance()
	{
		if (mInstance != nullptr)
		{
			delete mInstance;
			mInstance = nullptr;
		}
	}

private:
	CSingleton() {}
	virtual ~CSingleton() {}
	CSingleton(const CSingleton&) {}
	CSingleton& operator=(const CSingleton&) {}

private:
	static T *mInstance;
};

template<class T> T* CSingleton<T>::mInstance = nullptr;